#-*- coding:utf-8 -*-

"""
Django settings for kaoala_search project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'vaue6u=w)lp)^%epyewk%q2hn#=(i!7lg%%i-6*=a+hdr!g*6b'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_crontab',#django 定时触发器
    'rest_framework',
    'search',
    'kao_user',
    'kao_question',
    'kao_class',
    'area',
    'kao_kpoint',
    'kao_media',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'kaoala_search.urls'

WSGI_APPLICATION = 'kaoala_search.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    # 'default': {
    #     'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
    #     'NAME': 'test_1',                      # Or path to database file if using sqlite3.
    #     'USER': 'root',                      # Not used with sqlite3.
    #     'PASSWORD': '123456',                  # Not used with sqlite3.
    #     'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
    #     'PORT': '3306',                      # Set to empty string for default. Not used with sqlite3.
    # },
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'kaoala',                      # Or path to database file if using sqlite3.
        'USER': 'kaoala',                      # Not used with sqlite3.
        'PASSWORD': 'kaoala_admin',                  # Not used with sqlite3.
        'HOST': '101.201.36.12',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',                      # Set to empty string for default. Not used with sqlite3.
    },
    'word':{
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'search_data',                      # Or path to database file if using sqlite3.
        'USER': 'kaoala',                      # Not used with sqlite3.
        'PASSWORD': 'kaoala_admin',                  # Not used with sqlite3.
        'HOST': '101.201.36.12',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',
    }
}


DATABASE_ROUTERS = ['kaoala_search.database_router.DatabaseAppsRouter']
DATABASE_APPS_MAPPING = {
    # example:
    #'app_name':'database_name',
    'search': 'word',

}



CRONJOBS = (
    ('02 18 * * 3', 'django.core.management.call_command', ['search_source_handle'],{},'>> %s/assistant.log 2>&1' %os.path.join(BASE_DIR,'logs','backstage')),
    ('30 14 * * 2', 'django.core.management.call_command', ['word_dict_syncdb'],{},'>> %s/assistant.log 2>&1' %os.path.join(BASE_DIR,'logs','backstage')),
)

REST_FRAMEWORK = {
    'EXCEPTION_HANDLER': 'search.views.custom_exception_handler',  #自定义异常处理返回，覆盖了框架默认的处理
    #'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
     #'PAGINATE_BY': ,
    #"PAGINATE_BY_PARAM":'per_page',
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'zh-cn'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = False


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR,  'templates'),
)
SITE_ID = 1
"""
格式	      描述
%(name)s	   记录器的名称
%(levelno)s	数字形式的日志记录级别
%(levelname)s	日志记录级别的文本名称
%(filename)s	执行日志记录调用的源文件的文件名称
%(pathname)s	执行日志记录调用的源文件的路径名称
%(funcName)s	执行日志记录调用的函数名称
%(module)s	   执行日志记录调用的模块名称
%(lineno)s   执行日志记录调用的行号
%(created)s	执行日志记录的时间
%(asctime)s	日期和时间
%(msecs)s	    毫秒部分
%(thread)d  	线程ID
%(threadName)s	线程名称
%(process)d	进程ID
%(message)s	记录的消息
"""

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(name)s:%(lineno)d] [%(pathname)s-%(funcName)s] [%(levelname)s]- %(message)s'
        },
        'user':{
            'format': '%(asctime)s [%(name)s:%(lineno)d] [%(pathname)s-%(funcName)s] [%(levelname)s]- %(message)s'
        }
    },
    'filters': {
    },
    'handlers': {
         'request_handler': {
            'level':'INFO',
            'class':'logging.handlers.TimedRotatingFileHandler',
            'filename': os.path.join(BASE_DIR,'logs','django','django_system.log'), #或者直接写路径：'filename':'c:\logs\request.log''
            'when': 'midnight',   #午夜12点之后备份前一天的日志
            'delay': True,         #延时写入文件
            'formatter':'standard',
			# 'encoding':'utf-8',
        },
        'proscenium':{
            'level':'INFO',
             'class':'logging.handlers.TimedRotatingFileHandler',
            'filename': os.path.join(BASE_DIR,'logs','proscenium','proscenium.log'), #或者直接写路径：'filename':'c:\logs\user.log'
             'when': 'midnight',
            'delay': True,
            'formatter':'user',
            # 'encoding':'utf-8',
        },
        'backstage':{
            'level':'INFO',
             'class':'logging.handlers.TimedRotatingFileHandler',
            'filename': os.path.join(BASE_DIR,'logs','backstage','backstage.log'), #或者直接写路径：'filename':'c:\logs\user.log'
             'when': 'midnight',
            'delay': True,
            'formatter':'user',
			# 'encoding':'utf-8',
        }
    },
    'loggers': {
        'django.request': {   #django框架request 请求的一些错误信息
            'handlers': ['request_handler'],
            'level': 'INFO',
            'propagate': False
        },
        'proscenium':{   #前台的日志记录
            'handlers':['proscenium'],
            'level':'INFO',
            'propagate':False
        },
        'django_crontab.crontab':{     #中间数据应用日志
            'handlers':['backstage'],
            'level':'INFO',
            'propagate':False
        }
    }
}